package com.ioftv.util;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户上下文工具类
 * 用于从请求中获取当前登录用户信息
 */
public class UserContextUtil {
    
    /**
     * 从请求中获取用户ID
     * @param request HttpServletRequest
     * @return 用户ID
     */
    public static Long getCurrentUserId(HttpServletRequest request) {
        Object userId = request.getAttribute("userId");
        return userId != null ? (Long) userId : null;
    }
    
    /**
     * 从请求中获取用户名
     * @param request HttpServletRequest
     * @return 用户名
     */
    public static String getCurrentUsername(HttpServletRequest request) {
        Object username = request.getAttribute("username");
        return username != null ? (String) username : null;
    }
    
    /**
     * 从请求中获取用户角色
     * @param request HttpServletRequest
     * @return 用户角色
     */
    public static String getCurrentUserRole(HttpServletRequest request) {
        Object role = request.getAttribute("role");
        return role != null ? (String) role : null;
    }
}